﻿using aier.dataaccess.dapper;
using aier.dataaccess.model;
using aier.wx.nosql.redis;
using aier.xrm.wcf;
using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace aier.business.logic
{
    public class ScreenTemplateBll
    {
        public ScreenTemplateDal screenTemplateDal { get; set; }
        public RedisTestDal redisTestDal { get; set; }
        public ResResult resResult { get; set; }
        public CommonWcf commonWcf { get; set; }


        


        /// <summary>
        /// 更新模版（未完成）
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="scid"></param>
        /// <param name="new_templatetype"></param>
        /// <returns></returns>
        //public ResResult UpdateScreenTemplates(Guid userid,Guid scid, int new_templatetype) {
        //    try {
        //        Entity entity = new Entity("new_t_sc_page_element", scid);
        //        entity.Attributes.Add("",new_templatetype);
        //        if (Guid.Empty.Equals(userid))
        //        {
        //             commonWcf.UpdateEntityById(entity);
        //        }
        //        else
        //        {
        //           commonWcf.UpdateEntityProxyById(userid, entity);
        //        }
        //        return resResult.SuccessResult("成功");
        //    }
        //    catch (Exception ex)
        //    {
        //        return resResult.FailResult("ScreenTemplateBll->UpdateScreenTemplates Error:" + ex.Message);
        //    }

        //}




        /// <summary>
        /// 获取筛查模版
        /// </summary>
        /// <returns></returns>
        public List<ScreenTemplateView> GetScreenTemplates()
        {
            List<ScreenTemplateView> result = null;
            result = redisTestDal.Get<List<ScreenTemplateView>>("ScreenTemplateView");

            if (result != null && result.Count() > 0)
            {
                return result;
            }
            else
            {
                result = screenTemplateDal.GetScreenTemplates().ToList();
                redisTestDal.Set<List<ScreenTemplateView>>("ScreenTemplateView", result);
            }
            return result;
        }
    }
}
